import Mock from 'mockjs';

function getGoodList(options) {
  const { pageSize, page } =  options.query
  const result = Mock.mock({
    status: 'ok',
    'result|20': [
      {
        'id|1-100': 1,
        username: "@cname",
        'avatar': '@image("200x200", "#50B347")',
        description: '@cparagraph',
        'price|40-200.1-2': 1.0,
        unit: '个',
        'pictures|1-3': ['@image()'],
      }
    ],
    pagination: {
      total: 100,
      page: page ? Number(page) : 1,
      pageSize:  pageSize ? Number(pageSize) : 20,
    }
  });
  return result;
}

function getUserGoodList(options) {
  const { pageSize, page } =  options.query
  const result = Mock.mock({
    status: 'ok',
    'result|20': [
      {
        'id|1-100': 1,
        username: "@cname",
        'avatar': '@image("200x200", "#50B347")',
        description: '@cparagraph',
        'price|40-200.1-2': 1.0,
        unit: '个',
        'pictures|1-3': ['@image()'],
      }
    ],
    pagination: {
      total: 100,
      page: page ? Number(page) : 1,
      pageSize:  pageSize ? Number(pageSize) : 20,
    }
  });
  return result;
}

function getCollectGoodList(options) {
  const { pageSize, page } =  options.query
  const result = Mock.mock({
    status: 'ok',
    'result|20': [
      {
        'id|1-100': 1,
        username: "@cname",
        'avatar': '@image("200x200", "#50B347")',
        description: '@cparagraph',
        'price|40-200.1-2': 1.0,
        unit: '个',
        'pictures|1-3': ['@image()'],
      }
    ],
    pagination: {
      total: 100,
      page: page ? Number(page) : 1,
      pageSize:  pageSize ? Number(pageSize) : 20,
    }
  });

  return result;
}

function getGood(options) {
  console.log('options', options)
  const result = Mock.mock({
    status: 'ok',
    result: {
     
      'id|1-100': 1,
      username: "@cname",
      'avatar': '@image("200x200", "#50B347")',
      description: '@cparagraph',
      'price|40-200.1-2': 1.0,
      unit: '个',
      'pictures|1-3': ['@image()'],
    },
  });

  return result;
}

function createGood(data) {
  const result = Mock.mock({
    status: 'ok',
    result: {
      'id|1-100': 1,
      username: "user2",
      password: "user2",
      email: "user2@163.com",
      phone: "18888888888",
      authority: "normal",
    },
  });

  return result;
}

function modifyGood(data) {
  const result = Mock.mock({
    status: 'ok',
    result: {
      'id|1-100': 1,
      username: "user2",
      password: "user2",
      email: "user2@163.com",
      phone: "18888888888",
      authority: "normal",
    },
  });

  return result;
}




export default [
  {
    url: '/api/good',
    method: 'get',
    response: getGood,
  },
  {
    url: '/api/goods',
    method: 'get',
    response: getGoodList,
  },
  {
    url: '/api/good',
    method: 'post',
    response: createGood,
  },
  {
    url: '/api/good',
    method: 'put',
    response: modifyGood,
  },
  {
    url: '/api/goods/collect',
    method: 'get',
    response: getCollectGoodList,
  },
  {
    url: '/api/goods/user',
    method: 'get',
    response: getUserGoodList,
  },


  
];
